{% extends 'system_template/public/base_main.html' %}
{% block cite %}常用工具{% endblock %}
{% block content %}
    <form class="layui-form" id="form0" name="form0">
        <blockquote class="layui-elem-quote site-text">
            短网址生成器
        </blockquote>
        <div class="layui-form-item">
            <label class="layui-form-label">原网址</label>
            <div class="layui-input-inline">
                <input class="layui-input" id="web_txt" name="url" type="text" lay-verify="required|url" onkeyup="this.value=this.value.replace(/\s+/g,'')">
                <div class="layui-form-mid">* 短网址: <span style="color: red" id="webSite"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">生成类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="cls" value="0" title="dwz.lc" checked>
                    <input type="radio" name="cls" value="1" title="ons.red">
                    <input type="radio" name="cls" value="2" title="soso.bz">
                    <input type="radio" name="cls" value="3" title="maa.la">
                    <input type="radio" name="cls" value="4" title="ecx.cx">
                    <input type="radio" name="cls" value="5" title="did.red">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <a class="layui-btn" id="sub_0">生成网址</a>
            </div>
        </div>
    </form>
    <form class="layui-form" id="form1" name="form1">
        <blockquote class="layui-elem-quote site-text">
            百度索引提交
        </blockquote>
        {% for foo in form['indexes'] %}
            <div class="layui-form-item">
                <label class="layui-form-label">{{ foo.label }}</label>
                <div class="layui-input-inline">
                    {{ foo }}
                    {% if foo.name=='indexes_design' %}
                        <div class="layui-form-mid">* <span style="color: red">提交url的结构,请根据使用情况填写</span></div>
                    {% elif foo.name=='indexes_num' %}
                        <div class="layui-form-mid">* 默认:{{ foo.default }}条 (max/4000) <span style="color: red;">提交url的数量,提交链接-->最新优先</span></div>
                    {% endif %}
                </div>
            </div>
        {% endfor %}
        <div class="layui-form-item">
            <div class="layui-input-block">
                <a class="layui-btn" data-method="POST">保存并提交</a>
                <a class="layui-btn layui-btn-danger" data-method="UPDATE">仅保存</a>
            </div>

        </div>
    </form>
{% endblock %}
{% block footer %}
    <script>
        $('#form0').find('#sub_0').on('click', function () {
            var data = $("form[name='form0']").serializeArray();
            var url = $('#web_txt').val();
            if (url.length > 0) {
                $.ajax({
                    url: "{{ url_for('sys_bp.createUrl') }}",
                    type: 'POST',
                    data: data,
                    dataType: "json",
                    success: function (data) {
                        if (data.status === 0) {
                            $('#webSite').text(data.url);
                            layer.msg(data.msg, {icon: 1});
                        } else {
                            layer.msg(data.msg, {icon: 2});
                        }
                    }
                })
            } else {
                layer.msg('请输入正确的原网址', {icon: 7});
            }
        });
        $('#form1').find('.layui-btn').on('click', function () {
            var _method = this.getAttribute('data-method');
            subMethod('form1', _method, '{{ url_for('sys_bp.indexes') }}')
        });
    </script>
{% endblock %}